package com.itheima.jdbcTemplate;

import com.itheima.po.Account;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import java.util.List;

/**
 * ClassName:JdbcTemplateDemo
 * Package:com.itheima.jdbcTemplate
 * Description:jdbc的最基本用法
 * Date:2020/2/25 23:18
 * User: snow
 */
public class JdbcTemplateDemo {
	public static void main(String[] args) {
		//准备数据源，Spring的内置数据源
		DriverManagerDataSource dataSource = new DriverManagerDataSource();
		dataSource.setDriverClassName("com.mysql.jdbc.Driver");
		dataSource.setUrl("jdbc:mysql://localhost:3306/ssm");
		dataSource.setUsername("root");
		dataSource.setPassword("123");
		//1、创建jdbcTemplate对象
		JdbcTemplate jdbcTemplate = new JdbcTemplate();
		jdbcTemplate.setDataSource(dataSource);
		//2、执行操作
		// jdbcTemplate.execute("insert into account(name ,money) values ('Last',1000)");
/*		错误
		List<Account> accounts = jdbcTemplate.queryForList("select * from account",Account.class);
		for (Account account :accounts) {
			System.out.println(account);
		}*/
	}
}
